package  
{
	import net.flashpunk.Entity;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.FP;
	/**
	 * © 2012 TheJavaArcade.com
	 */
	public class Cagekey extends Entity {
		public var cagekeySprite:Image = new Image(Assets.CAGEKEY_SPRITE);
		public var level:int;
		public var state:int;
		
		public function Cagekey(theLevel:int) {
			graphic = cagekeySprite;
			type = "key"
			layer = -5;
			setHitbox(16, 16, 0, 0);
			level = theLevel;
			state = 1;
			visible = false;
			var dataList:XMLList;
			var dataElement:XML;
			dataList = GameEngine.levelXML[theLevel].items.key;
			for each(dataElement in dataList) {
				x = dataElement.@x;
				y = dataElement.@y;
			}
		}
		
		override public function update():void {
			if (state == 1 && GameEngine.level == level) {
				if (collide("fracas", x, y)) {
					GameEngine.score += 8000;
					state = 2;
					cagekeySprite.scale = .5;
					layer = -5;
				}
			}
			if (state == 3) FP.world.remove(this);
		}
		
	}

}